import rsa

def generate_rsa_keypair():
    # 生成 RSA 公私钥对
    public_key, private_key = rsa.newkeys(2048)
    with open("public.pem", "wb") as pub_file:
        pub_file.write(public_key.save_pkcs1())
    with open("private.pem", "wb") as priv_file:
        priv_file.write(private_key.save_pkcs1())
    print("RSA 密钥对已生成：public.pem, private.pem")

generate_rsa_keypair()
